<template>
  <div>
      <!-- <h1>登录</h1> -->
      <div>
        <van-cell-group>
        <van-field v-model="user.phone" label="手机号" placeholder="请输入手机号" />
      </van-cell-group>
      <van-cell-group>
        <van-field v-model="user.password" label="密码" placeholder="请输入密码" />
      </van-cell-group>
      <van-button type="warning"   @click="login">登录</van-button>
      </div>
  </div>
</template>

<script>
import axios from "axios";
import { Toast } from 'vant';

export default {
  data(){
    return {
      user:{
        phone:"",
        password:""
      }
    }
  },
  methods:{
    login(){
      axios({
        url:"/api/login",
        method:"post",
        data:this.user
      }).then(res=>{
        console.log(res);
        if(res.data.code==200){
          localStorage.setItem("islogin",1);
          localStorage.setItem("userInfo",JSON.stringify(res.data.list))
          Toast("登录成功");
          this.$router.push("/index");
        }
      })
    }
  }

}
</script>

<style scoped>

</style>